package com.netcombine.freewill.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.netcombine.freewill.constants.PageInfo;
import com.netcombine.freewill.lib.BCrypt;
import com.netcombine.freewill.lib.Paging;
import com.netcombine.freewill.manager.SessionManager;
import com.netcombine.freewill.service.UserService;
import com.netcombine.freewill.vo.FreewillVo;
import com.netcombine.freewill.vo.PagingVo;

@Controller
public class UserController{
//
	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private UserService userService;
	
	
	
	@RequestMapping(value = "/user/list.do")
	public String member_list(FreewillVo vo, HttpSession session, Model model){		
		
		if(!SessionManager.isLogin(session)){
			return PageInfo.GO_LOGIN;
		}			

			if(vo.getPage() == 0) vo.setPage(1);
			int total_cnt = userService.selectUserCount(vo);
			logger.info("total_cnt : " + Integer.toString(total_cnt));
		
			Paging paging = new Paging(vo.getPage(), total_cnt, PageInfo.PAGE_SIZE, PageInfo.BLOCK_PAGE, PageInfo.PAGING_SCRIPT);
			
			if(total_cnt != 0){
			
			// paging setting
				vo.setPageSize(paging.getPageSize());
				vo.setStartPosition(paging.getPageStart());			
			
				List<FreewillVo> userList = userService.selectUserList(vo);
			
				model.addAttribute("freewillVo", vo);
				model.addAttribute("userList", userList);
			}
				model.addAttribute(PageInfo.CURRENT_MENU, PageInfo.MENU_USER);
				model.addAttribute("paging", paging);

				return "user/list";
	}


	
}